<%--
  Created by IntelliJ IDEA.
  User: 王与刘
  Date: 12/11/2021
  Time: 下午12:51
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<html>
<head>
    <title>Title</title>
    <!-- jQuery (Bootstrap 的所有 JavaScript 插件都依赖 jQuery，所以必须放在前边) -->
    <script src="https://cdn.jsdelivr.net/npm/jquery@1.12.4/dist/jquery.min.js" integrity="sha384-nvAa0+6Qg9clwYCGGPpDQLVpLNn0fRaROjHqs13t4Ggj3Ez50XnGQqc/r8MhnRDZ" crossorigin="anonymous"></script>
    <!-- Bootstrap -->
    <link href="../../BookStrap/bootstrap-3.4.1-dist/css/bootstrap.min.css" rel="stylesheet">
    <script src="../../BookStrap/bootstrap-3.4.1-dist/js/bootstrap.min.js"></script>
    <link href="../../css/insert.css" rel="stylesheet" />
    <link href="../../css/query.css" rel="stylesheet" />
    <style>

    </style>
</head>
<body>
<div class="c">
    <h1 align="center">
        学吧<small>管理端</small>
    </h1>
</div>
<div class="container">
    <ul id="mytab" class="nav nav-pills nav-justified" role="tablist">
        <li role="presentation"><a href="../../index.jsp">首页</a></li>
        <li role="presentation" class="active"><a href="#">管理端</a></li>
        <li role="presentation"><a href="../../insert.jsp">添加题目</a></li>
    </ul>
</div>

<div align="center" >
    <table>
        <tr>
            <td class="q-id"><strong>编号</strong></td>
            <td class="q-explain"><strong>题目</strong></td>
            <td class="q-explain"><strong>题解</strong></td>
            <td class="q-answer"><strong>答案</strong></td>
            <td class="q-button"><strong>操作</strong></td>
        </tr>
        <c:forEach items="${requestScope.page.items}" var="question">
            <form method="post" action="update">
                <tr>
                    <td class="q-id"><input style="width: 100%;" name="pp" value="${question.id}" readonly="readonly"></td>
                    <td class="q-name"><textarea style="width: 100%;" id="name" name="name" rows="3">${question.question_name}</textarea></td>
                    <td class="q-explain"><textarea style="width: 100%;" id="explain" name="explain" rows="3">${question.question_explain}</textarea></td>
                    <td class="q-answer"><input style="width: 100%;" id="answer" name="answer" value="${question.question_answer}"></td>
                    <td class="q-button"><input class="btn btn-primary" type="submit" value="提交"> <a href="delete?pp=${question.id}" class="btn btn-danger">删除</a></td>
                </tr>
            </form>
        </c:forEach>
    </table>

<%--    大于首页才显示商业    --%>
        <c:if test="${requestScope.page.pageNo > 1 }">
            <a href="page?pageNo=1" class="btn btn-primary">首页</a>
            <a href="page?pageNo=${requestScope.page.pageNo-1}" class="btn btn-primary">上一页</a>
        </c:if>
        【${requestScope.page.pageNo}】
        <%--  如果已经是最后一页则不显示下一页,末页  --%>
        <c:if test="${requestScope.page.pageNo < requestScope.page.pageTotal }">
            <a href="page?pageNo=${requestScope.page.pageNo+1}" class="btn btn-primary">下一页</a>
            <a href="page?pageNo=${requestScope.page.pageTotal}" class="btn btn-primary">末页</a>
        </c:if>
        共${requestScope.page.pageTotal}页，${requestScope.page.pageTotalCount}条记录
        到第<input value="${param.pageNo}" name="pn" id="pn_input"/>页
        <input id="searchPageBtn" type="button" class="btn btn-primary" value="确定">

        <script type="text/javascript">
            $(function ()
            {
                //跳到指定页码
                $("#searchPageBtn").click(function ()
                {
                    var pageNo = $("#pn_input").val();
                    var pageTotal = ${requestScope.page.pageTotal};
                    if (pageNo < 0 || pageNo > pageTotal)
                    {
                        alert("输入范围错误");
                    }
                    else{
                        //JavaScript提供一个location地址栏对象
                        //它有一个属性叫做href，他可以获取浏览器地址栏中的地址
                        //href属性可读可写
                        location.href = "http://localhost:8080/XueDiaoTong_war_exploded/xue/api/page?pageNo=" + pageNo;
                    }
                });
            });
        </script>
</div>

<script language="JavaScript">
    function getMessage() {
        var username = '${sessionScope.myname}';
        if (username.indexOf("success") != -1)
            alert("操作成功");
    }
    getMessage()
</script>
</body>
</html>
